<template>
    <div class="mask">
        <div class="TMB-warp">
            <div class="titler">
                <span class="font-w fs16" style="font-weight: 700;">関連付け</span>
                <i class="el-icon-close" @click="CloseTables"></i>
            </div>
            <div class="middle">
                <div class="title">
                    <div class="seach">
                        <i class="el-icon-search" @click="getLineNoAssListApi"></i>
                    </div>
                    <el-input class="form-ipt" v-model="LineNo" @keyup.enter.native="getLineNoAssListApi"></el-input>
                </div>
                <ux-grid class="ux-table" ref="singleTable" :data="prposTabelData" :header-cell-style="{
                    color: 'rgba(0, 0, 0, 0.85)',
                    fontSize: '14px',
                    textAlign: 'left',
                    fontWeight: 'bold',
                    padding: 0,
                    height: '32px',
                    background: 'rgb(244,245,246)'
                }" :cell-style="{
                    color: 'rgba(96,98,102,1)',
                    fontSize: '14px',
                    textAlign: 'left',
                    padding: 0,
                    height: '32px',
                }" :checkbox-config="{
                    showHeader: false,
                }" @selection-change="handleSelectionChange" @current-change="handleCurrentChange"
                    highlight-current-row v-loading="loading" element-loading-spinner="el-icon-loading"
                    element-loading-background="#f8f8f8" :element-loading-text="$t('message.bhView.loading')"
                    height="500">
                    <template slot="empty"> No data </template>
                    <ux-table-column type="checkbox" width="40" align="center" title=""> </ux-table-column>
                    <ux-table-column property="label" title="利用状況">
                        <template slot-scope="scope">
                            <p>{{ scope.row.useStatus }}</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="ライン№">
                        <template slot-scope="scope">
                            <p>{{ scope.row.lineNo }}</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="FROM">
                        <template slot-scope="scope">
                            <p>{{ scope.row.macFrom }}</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="TO">
                        <template slot-scope="scope">
                            <p>{{ scope.row.macTo }}</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="適用法規">
                        <template slot-scope="scope">
                            <p>{{ scope.row.applicablelaw }}</p>
                        </template>
                    </ux-table-column>
                </ux-grid>
                <div class="footer">
                    <span>件数 = {{ cnt }} ライン</span>
                    <el-button type="primary" size="mini" @click="addLineNoAssociationApi">関連付け</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BASE from '@/utils/base'
import { getLineNoAssList, addLineNoAssociation, addBasicStyleTipsMsg } from '@/api/api'
import eventBus from "@/eventBus/bus";

export default {
    name: "RightTabelShow",
    props: {
        prposTabelData1: Array,
    },
    data() {
        return {
            prposTabelData: [
                // {
                //     test: 111
                // }
            ],
            loading: false,
            selectionArr: [],
            cnt: 0,
            LineNo: '',

        };
    },
    components: {},
    watch: {},
    methods: {
        handleSelectionChange(e) {
            console.log(e);
            this.selectionArr = e;
        },
        handleCurrentChange(val) {
            console.log(val);
        },
        okFn() {
            this.$emit('hidden');
        },
        CloseTables() {
            this.$emit('hidden')
        },
        async addLineNoAssociationApi() {

            let res = await addBasicStyleTipsMsg();
            this.$confirm(res.data.data, '', {
                confirmButtonText: 'OK',
                cancelButtonText: 'Cancel',
                type: 'warning'
            }).then(async () => {
                let dataJson = this.selectionArr.map(item => ({
                    MacCode: item.macCode,
                    DmgCode: this.$store.state.macCode,
                }));
                let res = await addLineNoAssociation(dataJson);
                if (!res) {
                    return
                }
                this.$message({
                    type: 'success',
                    message: res.data.msg
                });
                this.$emit('getBasicStyleProInfoApi')

                this.$emit('hidden')
            }).catch(() => {

            });

        },
        async getLineNoAssListApi() {
            this.loading = true;
            this.prposTabelData = [];
            this.cnt = 0;
            const MacCode = this.prposTabelData1.map(item => item.macCode);
            this.prposTabelData.length = 0;
            let dataJson = {
                PltCode: this.$store.state.pltCode,
                MacCode,
                MacType: 2,
                LineNo: this.LineNo
            }
            let res = await getLineNoAssList(dataJson);
            this.loading = false;

            if (res.data.code != 0) {
                return
            }
            // Object.assign(this.prposTabelData, res.data.data.list)
            this.prposTabelData = res.data.data.list;
            this.cnt = res.data.data.cnt;
        },
    },
    created() { },
    mounted() {
        this.getLineNoAssListApi();
    },
    beforeDestroy() { },
    destroyed() { },
    updated() {
        // 使用querySelectorAll选中所有带有.elx-cell--checkbox类的元素
        var elements = document.querySelectorAll('.elx-cell--checkbox');

        // 遍历这些元素  
        elements.forEach(function (element) {
            // 修改每个元素的title属性  
            element.setAttribute('title', '');
        })
    },
};
</script>
<style lang="scss" scoped>
.mask {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 500;


}

.TMB-warp {
    width: 800px;
    background: rgb(255, 255, 255);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
        0px 9px 28px 0px rgba(0, 0, 0, 0.08), 0px 6px 16px -8px rgba(0, 0, 0, 0.15);
    z-index: 100;

    .titler {
        height: 43px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 13px 24px;
        border-bottom: 1px solid #F0F0F0FF;

        i {
            cursor: pointer;
        }
    }

    .middle {
        padding: 13px 24px;

        .title {
            display: flex;
            margin-bottom: 13px;

            .seach {
                width: 24px;
                height: 24px;
                border-radius: 4px;
                border: 1px solid #d9d9d9;
                display: flex;
                align-items: center;
                justify-content: center;
                cursor: pointer;
                margin-right: 12px;
            }

            .form-ipt {
                height: 24px;

                ::v-deep .el-input__inner {
                    width: 197px;
                    height: 24px;
                    background: #fff;
                }
            }
        }

        ::v-deep .ux-table * {
            border: none;
        }

        ::v-deep .elx-table {
            border: 1px solid #00000026;
        }

        .table {
            border-bottom: 1px solid red !important;
        }

        .footer {
            height: 43px;
            background-color: #EDEEEFFF;
            border: 1px solid #00000026;
            border-top: none;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 4px;
        }
    }
}
</style>
